package com.jason.java.lib;

/**
 * @description: Test3
 * @author: ChenBaoYang
 * @createDate: 2022/2/23 5:29 下午
 */
public class Test3 {

    public static String longestNiceSubstring(String s) {

        char[] cs = s.toCharArray();
        int size = cs.length;
        String result = "";
        int start = -1;
        int end = -1;
        for(int i = 0; i < size-1; i++) {
            char x = cs[i];
            char y = cs[i+1];

            if(x>='A' && x<='Z'){
                x=(char)(x+32);
                if(x == y) {
                    start = start < 0 ? i: start;
                    end = i+1;
                }
                continue;
            }

            if(x>='a' && x<='z'){
                x=(char)(x-32);
                if(x == y) {
                    start = start < 0 ? i: start;
                    end = i+1;
                }
            }
        }
        if(start < 0) {
            return "";
        }
        end = end+1;
        result = s.substring(start,end);
        return result;
    }

    public static void main(String[] args) {
        String s = "YazaAay";
        System.out.println(longestNiceSubstring(s));
    }
}
